Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

204
Visualizações
Unit test -> Sinon + fluent-ffmpeg

I need some help with the following code:

const ffmpeg = require('fluent-ffmpeg'),
{PassThrough} = require('stream');

ffmpeg.setFfmpegPath('/opt/bin/ffmpeg');
ffmpeg.setFfprobePath('/opt/bin/ffprobe');

exports.wavCompilation = async (wavObjList, s3OutputFullPath) => {
    let command = ffmpeg();
    return new Promise(async (resolve, reject) => {

        const pt = new PassThrough()
        command
            .complexFilter(complexFilterList)
            .audioFrequency(44100)
            .audioChannels(2)
            .outputOptions('-map [audio]')
            .toFormat("wav")
            .output(pt, {end: true})
            .on('error', function (err, stdout, stderr) {
                console.log("stdout:\n" + stdout);
                console.log("stderr:\n" + stderr);
                if (err) {
                    console.log(err.message);
                    return reject("Error");
                }
            })
            .on('start', (commandLog) => printLog(commandLog))
            .on(`end`, () => console.info("end ffmpeg"))
            .run()

        resolve(***);
    });
}

Does anyone know how can I stub/mock/spy/fake "ffmpeg" ?

I use Sinon for unit tests and I'm trying to use proxyquire to mock "fluent-ffmpeg"

const sinon = require('sinon'),
proxyquire = require('proxyquire').noCallThru();

let ffmpegStub = {
    setFfmpegPath: () => {},
    setFfprobePath: () => {}
}

const ffmpegService = proxyquire('../services/ffmpeg-service/index', {
    'fluent-ffmpeg': ffmpegStub
});

for the methods setFfmpegPath and setFfprobePath it works but for the line:

let command = ffmpeg();

it says "ffmpeg is not a function"

I tried to add a default function such as:

let ffmpegStub = {
    default: () => {},
    setFfmpegPath: () => {},
    setFfprobePath: () => {}
}

but it also doesn't work and I have no idea now what I could do.

Please I need some fresh ideas, my goal is to catch the argument for "complexFilter" and assert it.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

No need of proxyquire.

I've got what I wanted with the following:

filterStub = sandbox.stub(ffmpeg.prototype, "complexFilter").returnsThis();
sandbox.stub(ffmpeg.prototype, "run").returnsThis();
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda